package com.youhong.teethcare.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.Drawable;

/**
 * Բ��ͷ��
 *
 * @author Administrator
 */
public class MyCircleHeadView extends Drawable {

    private Bitmap mBitmap;
    private Paint mPaint;
    private int mWidth;
    private Paint paint;
    private int outWidth;

    public MyCircleHeadView(Bitmap bitmap) {
        mBitmap = bitmap;
        if (mBitmap!=null) {

            BitmapShader bitmapShader = new BitmapShader(bitmap, TileMode.MIRROR, TileMode.MIRROR);
            mWidth = Math.min(mBitmap.getWidth(), mBitmap.getHeight());
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
            mPaint.setShader(bitmapShader);
        }

    }

    @Override
    public void draw(Canvas canvas) {

        canvas.drawCircle(mWidth / 2, mWidth / 2, mWidth / 2, mPaint);
    }

    @Override
    public int getIntrinsicWidth() {
        return mWidth;
    }

    @Override
    public int getIntrinsicHeight() {
        return mWidth;
    }

    @Override
    public void setAlpha(int alpha) {
        mPaint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        mPaint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}
